package jaux.tank.bean.entity.system;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;

@MappedSuperclass
public class BaseEntity extends EntityWithObjectId {

	public static final String DATETIME_FORMAT= "yyyy-MM-dd HH:mm:ss";
	
	@PrePersist
	private void modifyTimestamp() {
		createTime = DateTimeFormatter.ofPattern(DATETIME_FORMAT).format(LocalDateTime.now());
		updateTime = createTime;
	}
	@PreUpdate
	private void modifyUpdateTime() {
		updateTime = DateTimeFormatter.ofPattern(DATETIME_FORMAT).format(LocalDateTime.now());
	}

    private String createTime;

    private String updateTime;

    // getters and setters
    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public String getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(String updateTime) {
        this.updateTime = updateTime;
    }

}
